package com.rocksea.app.http;

import android.os.Looper;

import com.mor.dataacquisition.DataAcquisition;
import com.mor.dataacquisition.net.DataCallBack;
import com.mor.dataacquisition.net.parsedData.ResponseForLogin;
import com.rocksea.app.Account;
import com.rocksea.app.MyApplication;
import com.rocksea.app.utils.PerUtils;

public class UpDateRandomCodeTask extends Thread
{
    private Runnable runnable;

    private UpDateRandomCodeTask()
    {
        super("HttpThread");
    }
    private UpDateRandomCodeTask(Runnable runnable)
    {
        this();
        this.runnable = runnable;
    }

    @Override
    public void run()
    {
        if (runnable != null)
        {
            Looper.prepare();
            runnable.run();
            Looper.loop();
        }
    }

    public static void startTask()
    {
        new UpDateRandomCodeTask(upRandomCodeTask).start();
    }

    private static Runnable upRandomCodeTask = new Runnable()
    {
        @Override
        public void run()
        {
            DataAcquisition.getInstance().verifyAppUser(
                    Account.getAccount(),
                    "RS",
                    PerUtils.getString(Account.PASSWORD_KEY,""),
                    "12345678",
                    MyApplication.getContext(),
                    new DataCallBack<ResponseForLogin>()
                    {
                        @Override
                        public void processData(ResponseForLogin data)
                        {
                            super.processData(data);
                            if (data.returnCode.length() > 8)
                            {
                                Account.setRandomCode(data.returnCode);
                                PerUtils.setString(Account.RANDOM_CODE_KEY,data.returnCode);
                            }
                        }
                    }
            );
        }
    };


}
